﻿//文本收起	<div id="XXX" textheight="{Height:80,HideSize:280,TextId:'YYY',ShowButton:'AAA',HideButton:'BBB'}"><span id="YYY">Text<span><span id="AAA" style="display:none">[收起]</span><span id="BBB" style="display:none">[全文]</span></div>
(function(){
var TextHegiht=function()
	{
	this.GetArgument(arguments[0],{Id:null,Height:null,HideSize:null,TextId:null,ShowButton:null,HideButton:null,ScrollId:null,IsHide:1});
	this.HideId=this.TextId+'Hide';
	this.Start();
	};
(fastCSharp.Functions.TextHegiht=TextHegiht).Inherit(fastCSharp.BaseFunction,{
Start:function()
	{
	var Element=fastCSharp.$Id(this.Id),Input=Element.Element();
	if(Input!=this.Element)
		{
		this.Element=Input;
		fastCSharp.$Create('span').Id(this.HideId).InsertBefore(this.$Id(this.TextId)).Display(0);
		fastCSharp.$Id(this.ShowButton).AddEvent('click',fastCSharp.ThisFunction(this,this.Show));
		fastCSharp.$Id(this.HideButton).AddEvent('click',fastCSharp.ThisFunction(this,this.Hide));
		this.IsCheck=0;
		}
	if(!this.IsCheck)
		{
		this.IsCheck=1;
		if(fastCSharp.$Id(this.Id).Height()>this.Height)
			{
			fastCSharp.$Id(this.HideId).Html(fastCSharp.$Id(this.TextId).Text().Left(this.HideSize).ToHTML());
			this[this.IsHide?'Hide':'Show'](1);
			}
		}
	},
Show:function(NoScroll)
	{
	if(!TextHegiht.IsSetPageView)
		{
		this.IsHide=0;
		fastCSharp.$Id(this.HideId).Display(0);
		fastCSharp.$Id(this.ShowButton).Display(0);
		fastCSharp.$Id(this.TextId).Display(1);
		fastCSharp.$Id(this.HideButton).Display(1);
		if(!NoScroll)	fastCSharp.$ScrollTop(fastCSharp.$Id(this.ScrollId||this.TextId).XY().Top);
		TextHegiht.IsSetPageView=1;
		fastCSharp.PageView.OnSet();
		TextHegiht.IsSetPageView=0;
		}
	},
Hide:function(NoScroll)
	{
	this.IsHide=1;
	fastCSharp.$Id(this.TextId).Display(0);
	fastCSharp.$Id(this.HideButton).Display(0);
	fastCSharp.$Id(this.HideId).Display(1);
	fastCSharp.$Id(this.ShowButton).Display(1);
	if(!NoScroll)	fastCSharp.$ScrollTop(fastCSharp.$Id(this.ScrollId||this.HideId).XY().Top);
	}
		});
fastCSharp.CheckTextHegiht=function()
	{
	if(!this.TextHegihts)
		{
		this.TextHegihts={};
		this.PageView.OnSet.Add(this.ThisFunction(this,this.CheckTextHegiht));
		}
	if(!this.IsSetPageView)
		{
		for(var Elements=this.$('@textheight').GetElements(),Index=Elements.length;--Index>=0;)
			{
			var Element=Elements[Index];
			if(this.TextHegihts[Element.id])	this.TextHegihts[Element.id].Start();
			else	{
			var Parameter=eval('('+fastCSharp.$Attribute(Element,'textheight')+')');
				Parameter.Id=Element.id;
				this.TextHegihts[Element.id]=new this.Functions.TextHegiht(Parameter);
				}
			}
		}
	};
fastCSharp.OnLoad(fastCSharp.CheckTextHegiht,fastCSharp,1);
})();